﻿//-------------------------------------------------------------------
// VOString header file
//-------------------------------------------------------------------
//
// Copyright ?000-02 Virtual Office Systems Incorporated
// All Rights Reserved
//
// This code may be used in compiled form in any way you desire. This
// file may be redistributed unmodified by any means PROVIDING it is
// not sold for profit without the authors written consent, and
// providing that this notice and the authors name is included.
//
// This code can be compiled, modified and distributed freely, providing
// that this copyright information remains intact in the distribution.
//
// This code may be compiled in original or modified form in any private
// or commercial application.
//
// This file is provided "as is" with no expressed or implied warranty.
// The author accepts no liability for any damage, in any form, caused
// by this code. Use it at your own risk.
//-------------------------------------------------------------------
#pragma once




#define CH_QUOTE	TCHAR('\"')

class CVOString
{
public:
	CVOString(const CVOString& rSrc);
	CVOString(LPCTSTR pcszValue = L"");
	virtual ~CVOString();

	int FindOneOf(LPCTSTR pcszDelims) const;
	int CompareNoCase(LPCTSTR pcszValue) const;
	void MakeLower();
	void MakeUpper();
	CVOString Right(int nChars) const;
	const CVOString& TrimLeft();
	const CVOString& TrimRight();
	const CVOString& Trim();

	DWORD ReleaseBuffer(int nChars = -1);
	int ReverseFind(LPCTSTR pcszSubstring) const;
	int Find(LPCTSTR pcszValue, int nStartingOffset = 0) const;
	int Find(TCHAR chValue, int nStartingOffset = 0) const;
	LPTSTR GetBuffer(DWORD dwMinSize);
	CVOString Mid(DWORD nOffset, int nLength = -1) const;
	CVOString Left(DWORD dwCount) const;
	TCHAR GetAt(DWORD dwOffset) const;
	operator LPCTSTR() const;
	DWORD GetLength() const;
	void operator =(LPCTSTR pcszValue);
	void operator =(const CVOString& rSrc);
	BOOL operator == (LPCTSTR pcszValue) const;
	BOOL operator == (const CVOString& rValue) const;
	BOOL operator != (LPCTSTR pcszValue) const;
	BOOL operator != (const CVOString& rValue) const;
	LPCTSTR operator += (LPCTSTR pcszAppend);
	LPCTSTR operator += (TCHAR chAppend);
	CVOString operator + (LPCTSTR pcszAppend) const;
	DWORD Replace(LPCTSTR pcszSearchFor, LPCTSTR pcszReplaceWith);
	int _cdecl Format(LPCTSTR lpszFormat, ...);

	void Empty();
	BOOL IsEmpty() const;

	// Utility functions
public:
	BOOL LoadString(HINSTANCE hInstance, DWORD dwResourceID);
	BOOL Contains(LPCTSTR pcszValue, BOOL fMatchCase = TRUE) const;
	BOOL EndsWith(LPCTSTR pcszValue, BOOL fMatchCase = TRUE) const;
	BOOL StartsWith(LPCTSTR pcszValue, BOOL fMatchCase = TRUE) const;
	void MakeMixedCase();
	static CVOString DecodeHex(LPCTSTR pcszValue);
	static CVOString EncodeHex(LPCTSTR pcszValue);

	static CVOString AddQuotes(LPCTSTR pcszValue, TCHAR chQuote = CH_QUOTE);
	static CVOString RemoveQuotes(LPCTSTR pcszValue);
	static BOOL PopElement(CVOString& strValue, CVOString& strSource, const CVOString& strDelim);

protected:
	BOOL SetMinBufferSize(DWORD dwChars);

	TCHAR* m_pBuffer;
	DWORD m_dwLength;
	DWORD m_dwBufferSize;
};
